package org.javahispano.javacup.tacticas_aceptadas.jpautom.org.javahispano.javacup.tacticas.pitufos;

public class Analisis {
	Campo c;
	
	private Pos[] posInter=new Pos[22];
	private int[] tInter=new int[22];
	private int[] jPosesion;
	private int nPosesion;
	private int nPosesion1;
	
	
	public Analisis(Campo c) {
		this.c=c;
		analizar();
	}
	
	private void analizar() {
		int tmin=Integer.MAX_VALUE;
		
		for (int j=0; j<22; j++) {
			posInter[j]=new Pos();
			if (Util.tieneBola(c, j)) {
				tInter[j]=0;
				posInter[j]=(Pos)c.getJugador(j).getPos().clone();
			}
			else {
				tInter[j]=Util.intercepcion(c, j, posInter[j]);
			}
			if (tInter[j]<tmin) tmin=tInter[j];
		}

		int[] aux=new int[22];
		nPosesion=0;
		nPosesion1=0;
		for (int j=0; j<22; j++) {
			if (tInter[j]==tmin) {
				aux[nPosesion++]=j;
				if (j<11) nPosesion1++;
			}
		}
		jPosesion=new int[nPosesion];
		for (int i=0; i<nPosesion; i++)
			jPosesion[i]=aux[i];
	}

	public int[] getJPosesion() {
		return jPosesion;
	}

	public int getTPosesion() {
		return tInter[jPosesion[0]];
	}

	public Pos getPosPosesion() {
		return posInter[jPosesion[0]];
	}

	public double getValPosesion1() {
		return (double)nPosesion1/nPosesion;
	}

	public int getNJPosesion() {
		return nPosesion;
	}

	public Pos getPosIntercepcion(int j) {
		return posInter[j];
	}

	public int getTIntercepcion(int j) {
		return tInter[j];
	}
}
